﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace CMS.Class
{
    public class clsGridView
    {
        public clsGridView()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        private static String _strQpWeb = Constant.Connec;


        /// <summary>
        /// Dùng khi câu truy vấn là chuỗi sql,được gắn vào lưới
        /// </summary>
        /// <param name="grd"></param>
        /// <param name="sql"></param>
        public static void LoadGridView(GridView grd, String sql)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetData(sql);
            grd.DataSource = m_Tb;
            grd.DataBind();
        }

        /// <summary>
        /// Dùng khi câu truy vấn là sql có sử dụng cache,gắn giá trị vào lưới
        /// </summary>
        /// <param name="grd"></param>
        /// <param name="sql"></param>
        /// <param name="tableName"></param>

        public static void LoadGridView(GridView grd, String sql, String tableName)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetCache(tableName, sql);
            grd.DataSource = m_Tb;
            grd.DataBind();
        }


        public void LoadGridView(GridView grd, String commandText, CommandType commandType)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetData(commandText, commandType);
            grd.DataSource = m_Tb;
            grd.DataBind();
        }

        ///
        /// 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="grd"></param>
        /// <param name="tableName"></param>
        /// <param name="Parameters"></param>
        /// <param name="values"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>

        public static void LoadGridView(GridView grd, String tableName, String[] Parameters, Object[] values, String commandText, CommandType commandType)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);

            DataTable m_Tb = cls.GetCache(tableName, Parameters, values, commandText, commandType);
            grd.DataSource = m_Tb;
            grd.DataBind();
        }

        public static DataTable LoadGridView(String tableName, String[] Parameters, Object[] values, String commandText, CommandType commandType)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetCache(tableName, Parameters, values, commandText, commandType);
            return m_Tb;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="Parameters"></param>
        /// <param name="values"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <param name="time"></param>
        /// <returns></returns>

        public static DataTable LoadGridView(String tableName, String[] Parameters, Object[] values, String commandText, CommandType commandType, int time)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetCache(tableName, Parameters, values, commandText, commandType, time);
            return m_Tb;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="Parameters"></param>
        /// <param name="values"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <returns></returns>
        public static DataTable GetData(String tableName, String[] Parameters, Object[] values, String commandText, CommandType commandType)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetCache(tableName, Parameters, values, commandText, commandType);
            return m_Tb;
        }

        public static DataTable GetData(String tableName, String Parameter, Object value, String commandText, CommandType commandType)
        {
            QpWebConnec.QpConnec cls = null;
            cls = new QpWebConnec.QpConnec(_strQpWeb);
            DataTable m_Tb = cls.GetCache(tableName, Parameter, value, commandText, commandType);
            return m_Tb;
        }

    }
}
